import {Component, OnInit} from '@angular/core';
import {CluesService} from '../clues.service';
import {CluesItem} from '../clues-model';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {
    data: CluesItem[] = [];
    total = 0;
    pagesize = 10;
    pageCureent = 1;

    constructor(
        private cluesService: CluesService,
        private msgService: NzMessageService,
    ) {
    }

    ngOnInit() {
        this.getlist(this.pageCureent);
    }

    getlist($event) {
        this.pageCureent = $event;
        this.cluesService.getlist($event - 1).subscribe(res => {
            this.total = res.totalElement;
            this.pagesize = res.pageSize;
            this.data = res.list;
        });
    }

    del(item: CluesItem, index: number) {
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.cluesService.del(item.id).subscribe(res => {
            this.msgService.success('删除成功');
        }, error1 => {
            this.getlist(this.pageCureent);
        });
    }


}
